local hx__xunye = fk.CreateSkill{
  name = "hx__xunye",
  tags = { Skill.Switch, Skill.Compulsory },
}


hx__xunye:addEffect(fk.CardUseFinished, {
  anim_type = "switch",
  can_trigger = function(self, event, target, player, data)
    if player ~= target or not player:hasSkill(hx__xunye.name) or not data:isUsingHandcard(player) then return end
    local room = player.room
    local card_ids = Card:getIdList(data.card)
    if #card_ids == 0 then return end
    local yes = false
    room.logic:getEventsByRule(GameEvent.UseCard, 1, function (e)
      if e.id < room.logic:getCurrentEvent().id then
        yes = e.data.card.color ~= data.card.color or data.card.color == Card.NoColor
        return true
      end
    end, nil, Player.HistoryTurn)
    return yes
  end,
  on_use = function(self, event, target, player, data)
    player:filterHandcards()
  end,
})

hx__xunye:addEffect("filter", {
  mute = true,
  card_filter = function(self, card, player,isJudgeEvent)
    return player:hasSkill(hx__xunye.name) and card.color ~= Card.NoColor and ((table.contains(player.player_cards[Player.Hand], card.id) or isJudgeEvent))
  end,
  view_as = function(self, player, card)
    if player:getSwitchSkillState(hx__xunye.name, false) == fk.SwitchYang then
      if card.color == Card.Red then
        return Fk:cloneCard("nullification", card.suit, card.number)
      elseif card.color == Card.Black then
        return Fk:cloneCard("jink", card.suit, card.number)
      end
    else
      if card.color == Card.Red then
        return Fk:cloneCard("slash", card.suit, card.number)
      elseif card.color == Card.Black then
        return Fk:cloneCard("duel", card.suit, card.number)
      end
    end
  end,
})

return hx__xunye
